<html>
<body>
<p>Reports <code>while</code> loops, which spin on the
  value of a non-<code>volatile</code> field, waiting for it to be changed by another thread.</p>
<p>
In addition to being potentially extremely CPU intensive when little work is done inside the loop, such
loops likely have different semantics than intended. The Java Memory Model allows that loop to never complete even
if another thread changes the field's value.
</p>
<p><b>Example:</b></p>
<pre><code>
  class SpinsOnField {
      boolean ready = false;

      void run() {
          // the loop may never complete even after
          // markAsReady call from the other thread
          while (!ready) {
          }
          // do some work
      }

      void markAsReady() {
          ready = true;
      }
  }
</code></pre>
<p>
Additionally since Java 9, calling <code>Thread.onSpinWait()</code> inside spin loop
on a <code>volatile</code> field is recommended, which may significantly improve performance on some hardware.
</p>
<!-- tooltip end -->
<p>
Use the checkbox below to have this inspection report only empty <code>while</code> loops.
<p>
</body>
</html>
